package com.axxy.command;

/**
 * @author 一缕茜阳
 * @date 2021/7/29
 */
public class Control {

    private final Integer MAX_TASKS_NUMBER = 10;

    private Command[] commands;

    public Control() {
        commands = new Command[MAX_TASKS_NUMBER];
        for (int i = 0; i < MAX_TASKS_NUMBER; i++) {
            commands[i] = new NoCommand();
        }
    }

    public void setCommands(Command[] commands) {
        if (commands.length > MAX_TASKS_NUMBER) {
            for (int i = 0; i < MAX_TASKS_NUMBER; i++) {
                this.commands[i] = commands[i];
            }
            System.out.println("任务超载，下次执行");
        } else {
            for (int i = 0; i < commands.length; i++) {
                this.commands[i] = commands[i];
            }
        }
    }

    public void startTask(){
        for (Command c :
                commands) {
            c.execute();
        }
    }

}
